﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Collections;

namespace MM.Common.DBBase
{
    public class DataParamCol : NameObjectCollectionBase
    {
        // Methods
        public DataParamCol()
        {
        }

        public DataParamCol(params DataParam[] parms)
        {
            foreach (DataParam param in parms)
            {
                base.BaseAdd(param.Name, param);
            }
        }

        public DataParamCol(params object[] para)
        {
            this.AddBatch(para);
        }

        public void Add(DataParam dataParam)
        {
            base.BaseAdd(dataParam.Name, dataParam);
        }

        public void Add(string paraname, object paravalue)
        {
            base.BaseAdd(paraname, new InputDataParam(paraname, paravalue));
        }

        public void Add(string[] paraname, object[] paravalue)
        {
            for (int i = 0; i < paraname.GetLength(0); i++)
            {
                base.BaseAdd(paraname[i], new InputDataParam(paraname[i], paravalue[i]));
            }
        }

        public void AddBatch(params object[] para)
        {
            for (int i = 0; i < para.GetLength(0); i++)
            {
                string name = para[i].ToString();
                base.BaseAdd(name, new InputDataParam(name, para[i + 1]));
                i++;
            }
        }

        public void Clear()
        {
            base.BaseClear();
        }

        public IEnumerator GetEnumerator()
        {
            return new DataParamColEnumerator(this, base.GetEnumerator());
        }

        // Properties
        public DataParam this[string index]
        {
            get
            {
                return (DataParam)base.BaseGet(index);
            }
        }

        public DataParam this[int index]
        {
            get
            {
                return (DataParam)base.BaseGet(index);
            }
        }

        // Nested Types
        private class DataParamColEnumerator : IEnumerator
        {
            // Fields
            private DataParamCol _dataParamCol;
            private IEnumerator _enumerator;

            // Methods
            internal DataParamColEnumerator(DataParamCol dataParamCol, IEnumerator enumerator)
            {
                this._dataParamCol = dataParamCol;
                this._enumerator = enumerator;
            }

            public virtual bool MoveNext()
            {
                return this._enumerator.MoveNext();
            }

            public virtual void Reset()
            {
                this._enumerator.Reset();
            }

            // Properties
            public virtual object Current
            {
                get
                {
                    return this._dataParamCol[(string)this._enumerator.Current];
                }
            }
        }
    }
}
